package chat;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.KeyboardFocusManager;
import java.awt.Paint;
import java.awt.Point;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;

import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;

import javax.swing.JScrollPane;
import javax.swing.JLabel;

import java.awt.Color;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;

import custom.tree.EmployeesSearch;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.LineBorder;

public class ChatList extends JFrame {
	 
	EmployeesSearch em_f = new EmployeesSearch();
	Chatting chatting;
	private JPanel contentPane;
	private JList list;
	Point initialClick;
	boolean gained = false;
	static DefaultListModel<String> dl_list = new DefaultListModel();
	private JScrollPane scrollPane;
	private JPanel panel;
	private JLabel lblNewLabel_1;
	private JButton button;
	private JPanel panel_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ChatList frame = new ChatList();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public ChatList() {
		setUndecorated(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 150, 200);
		contentPane = new JPanel();
		contentPane.setBorder(new LineBorder(new Color(0, 0, 0)));
		contentPane.setBackground(new Color(152,191,218));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getScrollPane(), BorderLayout.CENTER);
		contentPane.add(getPanel(), BorderLayout.NORTH);
		
	}	
	
	public ChatList(DefaultListModel<String> dl_list) {
		setUndecorated(true);
		this.dl_list = dl_list;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 150, 400);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(152,191,218));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getScrollPane(), BorderLayout.CENTER);
		contentPane.add(getPanel(), BorderLayout.NORTH);
	}

	private JList getList() {
		if (list == null) {
			list = new JList(dl_list);
			list.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return list;
	}

	
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getList());
		}
		return scrollPane;
	}
	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setOpaque(false);
			panel.setBackground(new Color(152,191,218));
			panel.setForeground(new Color(176, 224, 230));
			panel.setBorder(new EmptyBorder(5, 5, 5, 5));
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getLblNewLabel_1(), BorderLayout.WEST);
			panel.add(getPanel_1_1(), BorderLayout.EAST);
			addMouseListener(new MouseAdapter() {
		        public void mousePressed(MouseEvent e) {
		             initialClick = e.getPoint();
		            getComponentAt(initialClick);
		        }				
		    });

		    addMouseMotionListener(new MouseMotionAdapter() {
		        @Override
		        public void mouseDragged(MouseEvent e) {

		            // get location of Window
		            int thisX = getLocation().x;
		            int thisY = getLocation().y;

		            // Determine how much the mouse moved since the initial click
		            int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
		            int yMoved = (thisY + e.getY()) - (thisY + initialClick.y);

		            // Move window to this position
		            int X = thisX + xMoved;
		            int Y = thisY + yMoved;
		            setLocation(X, Y);
		        }
		    });
		    
		    
			
		}
		return panel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("대화명단");
			lblNewLabel_1.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		}
		return lblNewLabel_1;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
				}
			});
			button.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\close.png"));
			button.setBorder(null);
			button.setBackground(new Color(152,191,218));
		}
		return button;
	}
	private JPanel getPanel_1_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setOpaque(false);
			panel_1.add(getButton());
		}
		return panel_1;
	}
}
